import React, { useEffect, useRef } from 'react'

function useLium(callBack,delay) {
    const  timer=useRef(null)

    useEffect(()=>{
        return ()=>{
            if(timer.current){
                clearTimeout(timer.current)
            }
        }
    },[])


  return (...arg)=>{
    if(timer.current){
        clearTimeout(timer.current)
    }
    timer.current=setTimeout(()=>{
        callBack(...arg)
    },delay)
  }
}

export default useLium
